<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">货位编码：</label>
                                    <div class="layui-input-inline mr0">
                                        <input name="code" class="layui-input" type="text"
                                               placeholder="请输入货位编码"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">仓库：</label>
                                    <div class="layui-input-inline mr0">
                                        <select id="warehouseId" name="warehouseId" lay-filter="warehouseId" lay-search
                                                lay-verify=""></select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">库区：</label>
                                    <div class="layui-input-inline mr0">
                                        <select id="warehouseAreaId" name="warehouseAreaId" lay-filter="warehouseAreaId"
                                                lay-search lay-verify=""></select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">货架：</label>
                                    <div class="layui-input-inline mr0">
                                        <select id="shelfId" name="shelfId" lay-search lay-verify=""></select>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit>查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="warehouseShelfSpaceTable" lay-filter="warehouseShelfSpaceTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="warehouseShelfSpaceTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="printBarcode">打印条码</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var element = layui.element;


        //仓库列表
        admin.initDataSelect("warehouse/warehouse/admin/administration/list", {limit: 9999}, "warehouseId", null, "仓库", null, null);
        //仓库选择事件
        form.on('select(warehouseId)', function (data) {
            $("#warehouseAreaId").empty();
            //仓库库区列表
            admin.initDataSelect("warehouse/warehouse/admin/warehouseFactoryArea/list", {
                limit: 9999,
                warehouseId: data.value
            }, "warehouseAreaId", null, "库区", null, null);
        });
        //仓库库区选择事件
        form.on('select(warehouseAreaId)', function (data) {
            $("#shelfId").empty();
            //库区货架列表
            admin.initDataSelect("warehouse/warehouse/admin/warehouseFactoryShelf/list", {
                limit: 9999,
                warehouseAreaId: data.value
            }, "shelfId", null, "库区货架", null, null);
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#warehouseShelfSpaceTable',
            url: config.base + 'warehouse/warehouse/admin/warehouseFactoryShelfSpace/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', width: 80}
                , {field: 'code', align: 'center', title: '货位编码'}
                , {field: 'warehouseName', align: 'center', title: '仓库'}
                , {field: 'warehouseAreaName', align: 'center', title: '库区'}
                , {field: 'shelfName', align: 'center', title: '货架'}
                , {field: 'description', align: 'center', title: '备注'}
                , {field: 'createTime', align: 'center', title: '创建时间', width: 180}
                , {align: 'center', toolbar: '#warehouseShelfSpaceTableBar', title: '操作', width: 200}
            ]]
        });

        // 工具条点击事件
        table.on('tool(warehouseShelfSpaceTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'printBarcode') { // 打印
                admin.getPrintBarcode('warehouse/warehouse/admin/warehousePalletBoxList/getBarCode', data.code);
            }
        });

        //监听排序
        table.on('sort(warehouseShelfSpaceTable)', function (obj) {
            table.reload('warehouseShelfSpaceTable', {
                initSort: obj,
                where: {
                    sort: obj.field,
                    order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });
    });
</script>